// get
export function Get(url, postData={}) {
  return new Promise((resolve, reject) => {
    if (postData) {
      let paramsArray = [];
      //拼接参数
      Object.keys(postData).forEach(key => paramsArray.push(key + '=' + postData[key]))
      if (url.search(/\?/) === -1) {
        url += '?' + paramsArray.join('&')
      } else {
        url += '&' + paramsArray.join('&')
      }
    }
    fetch(url, {
      method: "GET",
      mode: "cors",
      headers: {
        "Content-Type": "application/json",
      }
    }).then(resp => {
      return resp.json()
    }).then((res) => {
      resolve(res);
    }).catch(function (err) {
      reject(err);
    })
  })
}
// post
export function Post(url, postData={}) {
  return new Promise((resolve, reject) => {
    fetch(url, {
      method: 'POST',
      mode: 'cors',
      headers: {
        'X-CSRF-TOKEN': "{{csrf_token()}}",
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(postData)
    }).then((res)=>{
      return res.json()
    })
      .then((res) => {
        resolve(res);
      }).catch((err) => {
      reject(err)
    })
  })
}